package com.focusai.efairy.network.utils;

import android.os.Build;

import com.focusai.efairy.EFApplication;
import com.focusai.efairy.utils.AndroidUtils;
import com.focusai.efairy.utils.ScreenUtil;
import com.focusai.efairy.utils.URLEncodeUtils;


/**
 * Created by heqingbao on 2016/11/30.
 */
public final class HttpUtil {

    private static String userAgent;

    public static String genUserAgent() {
        if (userAgent == null) {
            String version = AndroidUtils.getVersionName(EFApplication.getContext());
            int screenWidth = ScreenUtil.getMetrics().widthPixels;
            int screenHeight = ScreenUtil.getMetrics().heightPixels;
            version = version.split("[-]")[0];
            String encodedBrand = URLEncodeUtils.encodeURL(Build.BRAND);
            String encodedModel = URLEncodeUtils.encodeURL(Build.MODEL);

            String tmp =  version + ";" + "Android "
                    + Build.VERSION.RELEASE + ";" + encodedBrand + ";" + encodedModel
                    + ";102"
                    + ";" + screenWidth + "*" + screenHeight
                    + ";deviceName:" + encodedBrand + " " + encodedModel
                    + ";os:Android " + Build.VERSION.RELEASE
                    + ";brand:" + encodedBrand
                    + ";model:" + encodedModel;

            userAgent = tmp;
        }

        return userAgent;
    }
}
